﻿#!/usr/bin/env python
#coding:utf-8
from probe.core.level import *
from commands import *
import os
def get_disk_wr(args):
    '''监控硬盘读写速度'''
    result = getoutput('''iostat -k|grep sda|awk '{print $3","$4}' ''')
    read, write = result.split(',')
    if float(read) >= args.get('WarningData') or float(write) >= args.get('WarningData'):
        return WarningData({'硬盘读取': [float(read),'KB/s'],'硬盘写入': [float(write),'KB/s']})
    return InfoData({'硬盘读取': [float(read),'KB/s'],'硬盘写入': [float(write),'KB/s']})
def disk_wr_able(args):
    '''监控硬盘是否可读可写'''
    wr_able = {}
    testfile = "/tmp/disk_wr_test"
    write_able = getstatusoutput('''echo 1234567890 > %s'''%testfile)
    read_able = getstatusoutput('''cat /tools/endpoint/ver.py''')
    if write_able[0]:
        wr_able['硬盘写入功能']=[write_able[0],'错误:%s'%write_able[1]]
    if read_able[0]:
        wr_able['硬盘读取功能']=[read_able[0],'错误:%s'%read_able[1]]
    os.remove(testfile)
    if wr_able:
        return WarningData(wr_able)
    return InfoData(wr_able)

if __name__ == '__main__':
    print get_disk_wr('')
